import { join } from 'path'
import fs from 'fs'
import { fileURLToPath } from 'url'
import { dirname } from 'path'

// 为ES模块提供__dirname和__filename
const __filename = fileURLToPath(import.meta.url)
const __dirname_local = dirname(__filename)

// 读取默认配置
function getDefaultConfig() {
  try {
    const configPath = join(__dirname_local, '../../config/app-defaults.json')
    const configData = fs.readFileSync(configPath, 'utf-8')
    return JSON.parse(configData)
  } catch (error) {
    console.warn('读取默认配置文件失败，使用硬编码默认值:', error.message)
    // 返回硬编码的默认值作为后备
    return {
      general: {
        theme: 'light',
        language: 'zh-CN'
      },
      performance: {
        threadCount: 4,
        cacheSize: '512MB'
      },
      network: {
        timeout: 30000,
        proxyEnabled: false
      }
    }
  }
}

export { getDefaultConfig }